home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / general / getlogin.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  597b  |  43 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #if 0
  6. char *getlogin (void)
  7. {
  8.   char *user = getenv("USER");
  9.  
  10.   return user ? user : "amiga";
  11. }
  12. char *cuserid (char *s)
  13. {
  14.   char *user = getenv("USER");
  15.  
  16.   if (user == NULL)
  17.     user = "amiga";
  18.   if (s)
  19.     strcpy (s, user);
  20.  
  21.   return s ? s : user;
  22. }
  23. #endif
  24. #include <pwd.h>
  25. #include <unistd.h>
  26. char *cuserid (char *s)
  27. {
  28.     struct passwd *pwd;
  29.  
  30.     if ((pwd = getpwuid(geteuid())) == NULL) {
  31.     if (s) {
  32.         *s = '\0';
  33.         return s;
  34.     }
  35.     }
  36.  
  37.     if (s) {
  38.     strncpy(s,pwd->pw_name,L_cuserid);
  39.     return s;
  40.     }
  41.     return pwd->pw_name;
  42. }
  43.